{% extends 'dns_manager/base.html' %}
{% load crispy_forms_tags %}

{% block title %}编辑云账号 - DNS管理系统{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-warning text-dark">
                <h4 class="mb-0">
                    <i class="bi bi-pencil me-2"></i>编辑云账号 - {{ account.name }}
                </h4>
            </div>
            
            <div class="card-body p-4">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label fw-semibold">账号名称 *</label>
                            {{ form.name }}
                            {% if form.name.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.name.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-md-6">
                            <label class="form-label fw-semibold">云服务商 *</label>
                            {{ form.provider }}
                            {% if form.provider.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.provider.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-12">
                            <label class="form-label fw-semibold">Access Key *</label>
                            {{ form.access_key }}
                            {% if form.access_key.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.access_key.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-12">
                            <label class="form-label fw-semibold">Secret Key</label>
                            {{ form.secret_key }}
                            {% if form.secret_key.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.secret_key.errors.0 }}
                                </div>
                            {% endif %}
                            <small class="form-text text-muted">
                                <i class="bi bi-shield-check text-success me-1"></i>
                                当前密钥已加密存储。留空则不修改现有密钥。
                            </small>
                        </div>
                        
                        <div class="col-md-6">
                            <label class="form-label fw-semibold">地域</label>
                            {{ form.region }}
                            {% if form.region.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.region.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-md-6 d-flex align-items-end">
                            <div class="form-check">
                                {{ form.is_active }}
                                <label class="form-check-label fw-semibold" for="{{ form.is_active.id_for_label }}">
                                    启用此账号
                                </label>
                            </div>
                        </div>
                    </div>
                    
                    <hr class="my-4">
                    
                    <!-- 账号统计信息 -->
                    <div class="row g-3 mb-4">
                        <div class="col-md-4">
                            <div class="bg-light rounded p-3 text-center">
                                <h5 class="text-primary mb-1">{{ account.domain_set.count }}</h5>
                                <small class="text-muted">关联域名</small>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="bg-light rounded p-3 text-center">
                                <h5 class="text-success mb-1">{{ account.created_at|date:"Y-m-d" }}</h5>
                                <small class="text-muted">创建日期</small>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="bg-light rounded p-3 text-center">
                                <h5 class="text-info mb-1">{{ account.updated_at|date:"m-d H:i" }}</h5>
                                <small class="text-muted">最后更新</small>
                            </div>
                        </div>
                    </div>
                    
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-warning">
                            <i class="bi bi-check me-1"></i>保存修改
                        </button>
                        <a href="{% url 'cloud_accounts' %}" class="btn btn-outline-secondary">
                            <i class="bi bi-x me-1"></i>取消
                        </a>
                        <a href="{% url 'delete_cloud_account' account.id %}" 
                           class="btn btn-outline-danger ms-auto"
                           onclick="return confirm('确定要删除此云账号吗？这将同时删除所有关联的域名和DNS记录！')">
                            <i class="bi bi-trash me-1"></i>删除账号
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}